home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 21 code / Custom GX Printer Drivers / CustomWriter GX 1.0.1 / ChooserSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  5.3 KB  |  220 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         ChooserSupport.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for PACK and LDEF resources used by the Chooser.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  14.                                     CustomBufferingAndIO.c.
  15.  
  16.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  17.                                     ImageWriter driver.
  18.  
  19.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  20.  
  21. */
  22.  
  23. #include "CommonDefines.h"
  24.  
  25.  
  26. /*    -----------------------------------------------------------------------
  27.  
  28.     Device is the standard Chooser "Device" routine that all QuickDraw GX
  29.     drivers require.
  30.  
  31.     -----------------------------------------------------------------------    */
  32.  
  33. pascal OSErr Device(short message, short caller, StringPtr objName, 
  34.                     StringPtr zoneName, ListHandle theList, long p2)
  35. {
  36.     
  37.     OSErr            anErr = noErr;
  38.     extern Str31     gDriverName;
  39.     StringPtr        pDriverName = &gDriverName;
  40.     extern gxJob    gJob;
  41.     gxJob            *pJob = &gJob;
  42.     
  43.     // start up GX.
  44.  
  45.     if (message == initializeMsg)
  46.     {
  47.         FCBPBRec    pb;
  48.  
  49.         // determine the driver name
  50.         pb.ioCompletion     = nil;
  51.         pb.ioNamePtr         = pDriverName;
  52.         pb.ioVRefNum         = 0;
  53.         pb.ioRefNum         = CurResFile();
  54.         pb.ioFCBIndx         = 0;
  55.         anErr = PBGetFCBInfo(&pb, false);
  56.  
  57.         *pJob = nil;
  58.         if (anErr == noErr)
  59.         {
  60.             GXEnterGraphics();
  61.             anErr = GXGetGraphicsError(nil);
  62.             if (anErr == noErr)
  63.             {
  64.                 anErr = GXInitPrinting();
  65.                 if (anErr != noErr)
  66.                     GXExitGraphics();
  67.             }
  68.         }
  69.     }
  70.         
  71.     // Let the system handle the choosing for us.
  72.  
  73.     if (anErr == noErr)
  74.     {
  75.         if ((*pJob != nil) || (message == initializeMsg))
  76.         {
  77.             anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  78.         
  79.             // Tear down GX when done.
  80.  
  81.             if ((message == terminateMsg) && (p2 == terminateMsg))
  82.             {
  83.                 GXExitPrinting();
  84.                 GXExitGraphics();
  85.             }
  86.         }
  87.     }
  88.         
  89.     return anErr;
  90. }
  91.  
  92.  
  93. /*    -----------------------------------------------------------------------
  94.     LDEF is our driver's Chooser LDEF.
  95.  
  96.     This is an LDEF that simply plots an icon, and lets the user "Create."
  97.  
  98.     -----------------------------------------------------------------------    */
  99.  
  100. pascal void LDEF(
  101.     short         message,        // What operation to perform on list
  102.     Boolean     select,            // Is this cell to be selected or not?
  103.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  104.     Cell        theCell,        // Which cell this is
  105.     short        dataOffset,        // Offset into data for this cell
  106.     short        dataLen,        // Length of data for this cell
  107.     ListHandle    theList)        // The list to act upon
  108.     {
  109.         Handle        cicnHdl;
  110.         Rect        iconRect;
  111.  
  112. #pragma unused(theCell, dataOffset, dataLen);
  113.  
  114.         switch (message)
  115.         {
  116.             case lInitMsg:
  117.                 {
  118.                     Cell    aCell = {0, 1};
  119.                     (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
  120.     
  121.                     if ((*theList)->userHandle)
  122.                     {
  123.                         DetachResource((*theList)->userHandle);
  124.                         LSetCell("Print To Disk", 13, aCell, theList);
  125.                         LSetSelect(true, aCell,theList);
  126.                     }
  127.                 }
  128.                 break;
  129.                 
  130.             case lCloseMsg:
  131.                 if ((*theList)->userHandle)
  132.                 {
  133.                     DisposeCIcon((CIconHandle) (*theList)->userHandle);
  134.                     (*theList)->userHandle = nil;
  135.                 }
  136.                 break;
  137.  
  138.             case lHiliteMsg:
  139.             case lDrawMsg:
  140.                 cicnHdl = (*theList)->userHandle;
  141.                 if (cicnHdl == nil) break;
  142.                 
  143.                 // draw the cell as an icon
  144.                 // center the icon rect on the list with a top margin of 10 pixels
  145.  
  146.                 iconRect.top = theRect->top + 10;
  147.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  148.                 iconRect.bottom = iconRect.top + 32;
  149.                 iconRect.right = iconRect.left + 32;
  150.                     
  151.                     
  152.                 // draw the icon
  153.  
  154.                 if (cicnHdl != nil)
  155.                     PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
  156.                                 
  157.                 // Get the general area under the icon in which to draw the label
  158.  
  159.                 iconRect.left = theRect->left + 2;
  160.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  161.                 iconRect.top = iconRect.bottom + 2;
  162.                 iconRect.bottom = theRect->bottom;
  163.         
  164.                 // use a nice small font for the label            
  165.  
  166.                 TextFont(applFont);
  167.                 TextSize(9);
  168.                     
  169.                 {
  170.                     short            labelWidth;
  171.                     short            rectWidth;
  172.                     short            labelHeight;
  173.                     FontInfo        theInfo;
  174.                     unsigned char    theHilightMode;
  175.                     
  176.     /*    Get rid of any previous label, compute the height of the new label,
  177.         compute where to draw the text, truncate the string to fit within the box,
  178.         compute the new width of the string, center the string, and draw it.
  179.     */
  180.                     EraseRect(&iconRect);
  181.                     iconRect.top += 2;
  182.                         
  183.                     GetFontInfo(&theInfo);
  184.                     labelHeight = theInfo.ascent +theInfo.leading;
  185.                 
  186.                     iconRect.bottom = iconRect.top + labelHeight;
  187.                     rectWidth = iconRect.right-iconRect.left;
  188.                     
  189.     // Not very localizable...  Use resources in the real world.
  190.  
  191.                     TruncString(rectWidth, "\pPrint To Disk", smTruncEnd);
  192.                     labelWidth = StringWidth("\pPrint To Disk");
  193.                 
  194.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  195.                     MoveTo(iconRect.left, iconRect.bottom);
  196.                     DrawString("\pPrint To Disk");
  197.  
  198.     // If selecting the icon, highlight the text.
  199.  
  200.                     if (select)
  201.                     {
  202.                         iconRect.right = iconRect.left + labelWidth;
  203.                         iconRect.bottom += theInfo.descent;
  204.                         
  205.                         InsetRect(&iconRect, -1, -1);
  206.                         
  207.                         theHilightMode = LMGetHiliteMode();
  208.                         BitClr(&theHilightMode, pHiliteBit);
  209.                         LMSetHiliteMode(theHilightMode);
  210.                         InvertRect(&iconRect);
  211.                     }
  212.  
  213.                     TextFont(applFont);
  214.                     TextSize(0);
  215.                 }
  216.                 break;
  217.         }
  218. }
  219.  
  220.